package com.zryc.shop.ums.mapper;

import com.zryc.shop.ums.entity.Menu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zryc.shop.ums.entity.Role;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 后台菜单表 Mapper 接口
 * </p>
 *
 * @author LiYe
 * @since 2023-02-02
 */
@Repository
public interface MenuMapper extends BaseMapper<Menu> {
    /**
     * 根据管理员ID查询(其有权限访问的)菜单列表
     * @param adminId 管理员ID
     * @return
     */
    @Select("SELECT * FROM ums_menu WHERE id IN " +
            "(SELECT menu_id FROM ums_role_menu_relation WHERE role_id IN " +
            "(SELECT role_id FROM ums_admin_role_relation WHERE admin_id = #{param1}))")
    List<Menu> selectListByAdminId(Long adminId);

    /**
     * 使用角色ID查询菜单列表
     * @param roleId 角色ID
     * @return
     */
    @Select("SELECT * FROM ums_menu WHERE id IN (SELECT menu_id FROM ums_role_menu_relation WHERE role_id = #{param1})")
    List<Menu> selectListByRoleId(Long roleId);
}
